package com.pubinfo.passbook.engine.process.variable.medicine;

import com.pubinfo.passbook.common.model.dto.witeoff.MedicineOnJobOrRetireDTO;
import com.pubinfo.passbook.common.model.ruler.PayInformation;
import com.pubinfo.passbook.common.service.ruler.CheckService;
import com.pubinfo.passbook.common.service.ruler.InformationService;
import com.pubinfo.passbook.engine.utils.ApplicationContextUilts;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.List;

/**
 * 个人账户支付金额
 *
 * @author zhouch
 * @date 2022/3/8 15:24
 */
@Slf4j
public class AccountPayAmountProcessor extends MedicineVariableProcessor {


    @Override
    public String getName() {
        return "个人账户支付金额";
    }

    @Override
    public BigDecimal get(MedicineOnJobOrRetireDTO data) {

        log.info("执行参数处理器: {}", this.getClass().getSimpleName());

        List<PayInformation> payInformations = cache.getPayInformationData();

        BigDecimal accountPayAmounts = new BigDecimal(0);

        for (PayInformation payInformation : payInformations) {

            BigDecimal accountPayAmount = payInformation.getAccountPayAmount();
            if (accountPayAmount.equals(new BigDecimal(-0.0000999))) {
                cache.markNeedAudit();
                log.info("{} ==> 需要人工审核.", getClass().getName());
                accountPayAmount = BigDecimal.ZERO;
            }
            accountPayAmounts = accountPayAmounts.add(accountPayAmount);

        }

        log.info("参数处理器: {} 结果: {}", this.getClass().getSimpleName(), accountPayAmounts);

        outputComputeMessage(accountPayAmounts.toString());

        return accountPayAmounts;
    }
}
